/*
 * SN76489_instruction.hpp
 *
 *  Created on: Jan 1, 2012
 *      Author: douglas
 */

//I'm using a union to implement the data to be writen, and I called this data, "instruction".
//Doing this way I can get the data field directly, without doing binary manipulation, so
//the implementation is much more clean and easier.
//I saw this type of code in the Gekko.h code (see Dolphin emulator).
union SN76489_instruction
{
	uint8 hex;

	SN76489_instruction(_hex) { hex = _hex; }
	SN76489_instruction()     { hex = 0; }

	//This struct is only to check the type of write.
	struct
	{
		uint8 datatype   :  1; //0 is Data Byte; 1 is Latch Byte.
		uint8            :  7;
	};

	//Latch byte - Byte 7 is 1.
	struct
	{
		uint8            :  1;
		uint8  channel   :  2; //we will latch in this channel.
		uint8  regtype   :  1; //tone/noise (0) or volume (1) register?
		uint8  low4bits  :  4; //Data to be writen at 4 low bits of the register (tone, noise or volume).
	};

	//Data byte - Byte 7 is 0.
	struct
	{
		uint8            :  2;
		uint8  high6bits :  6; //data to be writen in the high 6 bits of a tone register.
	};

};
